<script setup>
import { onMounted,watch } from 'vue'
import EzuikitFlv from 'ezuikit-flv'

let player = null;

const props = defineProps({
  id: {
    type: String,
    default: 'flv-player'
  },
  url: {
    type: String,
    default: ''
  }
})

watch(props.url, (newVal, oldVal) => {
  if (player) {
    player.destroy();
    player = null;
  }
  if (newVal) {
    player = new EzuikitFlv({
      container: document.getElementById(props.id),
      debug: false,
      url: newVal,
      useMSE: true,
      decoder: 'decoder.js' // 软解解码资源 （wasm 要和js 在同一个文件夹中）
    })
    player.play();
    player.closeSound();
  }
})

onMounted(() => {
  if (props.url) {
    player = new EzuikitFlv({
      container: document.getElementById(props.id),
      debug: false,
      url: props.url,
      useMSE: true,
      decoder: 'decoder.js' // 软解解码资源 （wasm 要和js 在同一个文件夹中）
    })
    player.play();
    player.closeSound();
  }

})
</script>

<template>
  <div :id="id" class="video"></div>
</template>

<style>
</style>
